package com.cooper.pagination;

import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 
 * @Description: <br>
 * @Date: Jan 18, 2014 5:13:51 PM<br>
 * @Copyright (c) 2014 MiXuan <br> * 
 * @since 1.0
 * @author coral
 */
public class PageResult<T> {
	
	private final boolean success;

	private final List<T> result;

	private final PageInfo pageInfo;

	private String errCode;

	private String errMsg;

	public PageResult(List<T> result, PageInfo pageInfo) {
		this.success = true;
		this.result = result;
		this.pageInfo = pageInfo;
	}

	public static <T> PageResult<T> newErr(String errCode, String errMsg) {
		return new PageResult<T>(errCode, errMsg);
	}

	private PageResult(String errCode, String errMsg) {
		this.success = false;
		this.result = null;
		this.errCode = errCode;
		this.errMsg = errMsg;
		this.pageInfo = null;
	}

	public boolean isSuccess() {
		return success;
	}

	public List<T> getResult() {
		return result;
	}

	public String getErrCode() {
		return errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public PageInfo getPageInfo() {
		return pageInfo;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
	
}
